<?php
//Nguyen Van Binh
//suongmumc@gmail.com

defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
$tpl = new TemplatePower("template/home.htm");
$tpl->prepare();
$tpl->assignGlobal("site_address",$site_address);

// news 
	$sql="SELECT * FROM cat WHERE active=1 AND inhome=1 ORDER BY thu_tu DESC, name ASC";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$tpl->newBlock("newshome");
		$tpl->assign("catname",$rs['name']);	
		$tpl->assign("link",$rs['url']);
		$sql1="SELECT * FROM news WHERE active=1 AND id_cat IN(".Get_Id_Cat($idc).") ORDER BY thu_tu DESC, id_news DESC";
		$db1=$DB->query($sql1);
		$db1=phan_trang_rewrite($_GET['p'],$site_address.get_url_news($rs['id_cat']),$sql1,8,1);
		while($rs1=mysql_fetch_array($db1['db'])){
			$tpl->newBlock("itemhome");
			$tpl->assign("name",$rs1['name']);
			$tpl->assign("intro",$rs1['intro']);	
			if ($rs1['small_image']){
				$tpl->assign("image","<img alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' align='left' border='0'  class='imagenews'  >");
			}	
			$tpl->assign("link_detail",$site_address.get_url_news($rs['id_cat']).clean_url($rs['name'])."_".$rs['id_news'].'.html');
		}
	}

// san pham moi
	$sql1="SELECT * FROM product WHERE active=1 AND moi=1 ORDER BY thu_tu DESC, name ASC";				
			$db1=phan_trang_rewrite($_GET['p'],$site_address.get_url_product($idc),$sql1,8,9);
			while($rs1=mysql_fetch_array($db1['db']))	{
				$tpl->newBlock('new_cell');				
				$tpl->assign("name",$rs1['name']);
				if(file_exists($CONFIG['upload_image_path'].$rs1['small_image'])){	
					$size=getimagesize($CONFIG['upload_image_path'].$rs1['small_image']);
					if($size[0]>$size[1]){
						$tpl->assign("image","<img width='167' alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' border='0'>");
					}else{
						$tpl->assign("image","<img height='142' alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' border='0' class='borderimage_product_list'>");
					}
				}
				$tpl->assign("link_detail",$site_address.get_url_product($rs1['id_catpd']).clean_url($rs1['name'])."_".$rs1['id_product'].'.html');
			}			
			$tpl->assignGlobal("pages",$db1['cac_trang']);
$tpl->printToScreen();

?>